import axios from '@/api'
import { IGrain } from './famer'
import { IProject } from './user'

export interface ISubsidy extends IGrain, ISubsidyBase {
  is_used: string;
  member_id: string;
  member_nam: string;
  member_addr: string
}

export interface ISubsidyBase {
  iid: string;
  s_a_id: string;
  s_a_nam: string;
}

export interface IStatistics extends ISubsidyBase {
  used: string;
  member_total: string;
}

export interface IGetSubsidyList {
  request: {
    s_a_id: string;
  },
  response: Array<ISubsidy | IStatistics>
}

export interface IGetSubsidyStandard {
  response: {
    task_id: string;
    task_nam: string;
    task_doc: string;
    s_a_nams: string;
    pay_info: ISubsidyStandard[];
  }
}
export interface ISubsidyStandard {
  s_a_id: string;
  s_a_nam: string;
  pay_unit: string;
  pay_price: string;
  islock: boolean;
}

export interface IPayBatch {
  s_a_id: string;
  task_id: string;
  batch_id: string;
  batch_type: string;
  batch_num: string
}

class SubsidyServices {
  constructor() { }

  /**
   * 获取补贴名单
   *
   * @returns
   * @memberof SubsidyServices
   */
  async getSubsidyList(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseOptions<IGetSubsidyList['response']>>('/btbusiness/task-plan/get-area-member-list', data)
  }

  /**
   * 设置补贴状态
   *
   * @param {(Pick<ISubsidy, 'member_id' | 'is_used'>)} data
   * @returns
   * @memberof SubsidyServices
   */
  setSubsidyStatus(data: Partial<Pick<ISubsidy, 'is_used' | 'iid' | 's_a_id'>> & { is_area?: boolean, big_mb_id?: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/task-plan/set-member-used', data)
  }

  /**
   * 获取项目补贴标准列表
   *
   * @returns
   * @memberof SubsidyServices
   */
  getSubsidyStandard() {
    return axios.post<unknown, Api.ResponseOptions<IGetSubsidyStandard['response']>>('/btbusiness/task-standard/get-standard')
  }

  /**
   * 更新项目补贴标准
   *
   * @param {(Pick<ISubsidyStandard, 'pay_unit' | 'pay_price'>)} data
   * @returns
   * @memberof SubsidyServices
   */
  updateSubsidyStandard(data: Partial<ISubsidyStandard>) {
    return axios.post<unknown, Api.ResponseOptions<IGetSubsidyStandard['response']>>('/btbusiness/task-standard/edit-standard', data)
  }

  /**
   * 更新补贴锁定状态
   *
   * @param {{
   *     s_a_id: string;
   *     task_id?: string;
   *     s_state?: number;
   *   }} data
   * @returns
   * @memberof SubsidyServices
   */
   updateSubsidyLockStatus(data: {
    s_a_id: string;
    task_id?: string;
    s_state?: number;
  }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/task-standard/edit-area-lock', data)
  }

  /**
   * 获取发放批次信息
   *
   * @param {(Pick<IPayBatch, 's_a_id' | 'task_id'>)} data
   * @returns
   * @memberof SubsidyServices
   */
  getPayBatchLists(data: Pick<IPayBatch, 's_a_id' | 'task_id'>) {
    return axios.post<unknown, Api.ResponseOptions<IPayBatch[]>>('/btbusiness/task-standard/get-pay-batch', data)
  }

  /**
   * 更新发放批次信息
   *
   * @param {Partial<IPayBatch>} data
   * @returns
   * @memberof SubsidyServices
   */
  updatePayBatch(data: Partial<IPayBatch>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/task-standard/edit-pay-batch', data)
  }

  /**
   * 删除发放批次信息
   *
   * @param {(Pick<IPayBatch, 's_a_id' | 'task_id'>)} data
   * @returns
   * @memberof SubsidyServices
   */
  deletePayBatch(data: Pick<IPayBatch, 's_a_id' | 'task_id'>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/task-standard/remove-pay-batch', data)
  }

}

export const subsidyServices = new SubsidyServices()

export default subsidyServices
